﻿#region Namespace References

using System;
using System.Data;
using DynConDevCorp.OpenArch.SmartData.Core;
using DynConDevCorp.OpenArch.SmartData.Interfaces;
using DynConDevCorp.OpenArch.SmartData.Interfaces.EventArgClasses;
using Microsoft.VisualStudio.TestTools.UnitTesting;

#endregion

namespace UnitTest.DynConDevCorp.OpenArch.SmartData
{
    /// <summary>
    ///This is a test class for SmartField_UnitTests and is intended
    ///to contain all SmartField_UnitTests Unit Tests
    ///</summary>
    [TestClass]
    public class SmartField_UnitTests
    {
        #region Public Instance Properties

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get { return testContextInstance; }
            set { testContextInstance = value; }
        }

        #endregion

        #region Public Instance Methods

        /// <summary>
        ///A test for Commit
        ///</summary>
        [TestMethod]
        public void Commit_UnitTest()
        {
            SmartField<int> target = new SmartField<int>();
            target.EnableTrackChanges(true);
            target.Value = 123;
            target.Commit();
        }


        /// <summary>
        ///A test for DataType
        ///</summary>
        [TestMethod]
        public void DataType_UnitTest()
        {
            SmartField target = new SmartField<double>();
            Type actual = target.DataType;
            Assert.AreSame(typeof (double), actual);
        }

        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup]
        //public void MyTestCleanup()
        //{
        //}
        //

        [TestMethod]
        public void DisplayFormatter_UnitTest()
        {
            DisplayFormatter_UnitTestHelper<int>();
        }

        /// <summary>
        ///A test for DisplayFormatter
        ///</summary>
        public void DisplayFormatter_UnitTestHelper<DATA_TYPE>()
            where DATA_TYPE : IComparable<DATA_TYPE>
        {
            SmartField<DATA_TYPE> target = new SmartField<DATA_TYPE>(); 
            const ISmartDisplayFormatter<DATA_TYPE> expected = null;
            target.DisplayFormatter = expected;
            ISmartDisplayFormatter<DATA_TYPE> actual = target.DisplayFormatter;
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for DisplayValue
        ///</summary>
        [TestMethod]
        public void DisplayValue_UnitTest()
        {
            SmartField<int> target = new SmartField<int>();
            target.Value = 123;
            string expected = target.Value.ToString();
            string actual = target.DisplayValue;
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for EnableTrackChanges
        ///</summary>
        [TestMethod]
        public void EnableTrackChanges_UnitTest()
        {
            SmartField target = new SmartField<int>(); 
            target.EnableTrackChanges(true);
            target.EnableTrackChanges(false);
        }

        /// <summary>
        ///A test for FormattedDisplay
        ///</summary>
        [TestMethod]
        public void FormattedDisplay_UnitTest()
        {
            SmartField<int> target = new SmartField<int>(); 
            string formatString = string.Empty; 
            const string expected = "123";
            target.Value = 123;
            string actual = target.FormattedDisplay(formatString);
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for InputInhibited
        ///</summary>
        [TestMethod]
        public void InputInhibited_UnitTest()
        {
            SmartField target = new SmartField<int>(); 
            const bool expected = false;
            target.InputInhibited = expected;
            bool actual = target.InputInhibited.ToBoolean();
            Assert.AreEqual(expected, actual);
        }

        [TestMethod]
        public void InputParser_UnitTest()
        {
            InputParser_UnitTestHelper<int>();
        }

        /// <summary>
        ///A test for InputParser
        ///</summary>
        public void InputParser_UnitTestHelper<DATA_TYPE>()
            where DATA_TYPE : IComparable<DATA_TYPE>
        {
            SmartField<DATA_TYPE> target = new SmartField<DATA_TYPE>(); 
            const ISmartInputParser<DATA_TYPE> expected = null;
            target.InputParser = expected;
            ISmartInputParser<DATA_TYPE> actual = target.InputParser;
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for InputValue
        ///</summary>
        [TestMethod]
        public void InputValue_UnitTest()
        {
            SmartField<int> target = new SmartField<int>(); 
            target.InputValue = "123";
            Assert.AreEqual(123, target.Value);
        }

        /// <summary>
        ///A test for OwningEntity
        ///</summary>
        [TestMethod]
        public void OwningEntity_UnitTest()
        {
            SmartField target = new SmartField<int>();
            ISmartEntity actual = target.OwningEntity;
            Assert.IsNull(actual);
        }


        /// <summary>
        ///A test for RawValue
        ///</summary>
        [TestMethod]
        public void RawValue_UnitTest()
        {
            SmartField target = new SmartField<int>();
            object expected = 123;
            target.RawValue = expected;
            object actual = target.RawValue;
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for WriteLocked
        ///</summary>
        [TestMethod]
        public void ReadOnly_UnitTest()
        {
            ISmartField target = new SmartField<int>();
            target.WriteLocked = true;
            Assert.IsTrue(target.WriteLocked.ToBoolean());
            target.WriteLocked = false;
            Assert.IsFalse(target.WriteLocked.ToBoolean());
        }

        /// <summary>
        ///A test for WriteLocked
        ///</summary>
        [TestMethod]
        [ExpectedException(typeof(ReadOnlyException))]
        public void ReadOnly_Value_UnitTest()
        {
            ISmartField<int> target = new SmartField<int>();
            target.WriteLocked = true;
            target.Value = 123;
            Assert.AreNotEqual(123, target.Value);
            target.WriteLocked = false;
            Assert.IsFalse(target.WriteLocked.ToBoolean());
        }

        /// <summary>
        ///A test for Rollback
        ///</summary>
        [TestMethod]
        public void RollBack_UnitTest()
        {
            SmartField<int> target = new SmartField<int>();
            target.EnableTrackChanges(true);
            target.Value = 123;
            target.Rollback();
        }

        /// <summary>
        ///A test for SmartField Constructor
        ///</summary>
        [TestMethod]
        public void SmartFieldConstructor_UnitTest()
        {
            SmartField target = new SmartField<int>();
            Assert.IsNotNull(target);
        }

        [TestMethod]
        public void SmartFieldConstructor_UnitTest1()
        {
            SmartFieldConstructor_UnitTest1Helper<int>();
        }

        /// <summary>
        ///A test for SmartField`1 Constructor
        ///</summary>
        public void SmartFieldConstructor_UnitTest1Helper<DATA_TYPE>()
            where DATA_TYPE : IComparable<DATA_TYPE>
        {
            SmartField<DATA_TYPE> target = new SmartField<DATA_TYPE>();
            Assert.IsNotNull(target);
        }

        [TestMethod]
        public void Value_UnitTest()
        {
            Value_UnitTestHelper<int>();
        }

        /// <summary>
        ///A test for Value
        ///</summary>
        public void Value_UnitTestHelper<DATA_TYPE>()
            where DATA_TYPE : IComparable<DATA_TYPE>
        {
            SmartField<DATA_TYPE> target = new SmartField<DATA_TYPE>(); 
            DATA_TYPE expected = default(DATA_TYPE);
            target.Value = expected;
            DATA_TYPE actual = target.Value;
            Assert.AreEqual(expected, actual);
        }


        /// <summary>
        ///A test for SetOwningEntity
        ///</summary>
        [TestMethod]
        public void SetOwningEntity_UnitTest()
        {
            SmartField target = new SmartField<int>();
            target.SetOwningEntity(null);
        }


        /// <summary>
        ///A test for ToString()
        ///</summary>
        [TestMethod]
        public void ToString_UnitTest()
        {
            SmartField target = new SmartField<int>();
            String actual = target.ToString();
            Assert.IsNotNull(actual);
        }

        /// <summary>
        ///A test for RawValueChanged()
        ///</summary>
        [TestMethod]
        public void RawValueChanged_UnitTest()
        {
            SmartField target = new SmartField<int>();
            target.RawValueChanged += target_RawValueChanged;
            m_RawValueChanged_Fired = false;
            target.RawValue = 123;
            Assert.IsTrue(m_RawValueChanged_Fired);
            target.RawValueChanged -= target_RawValueChanged;
        }

        private bool m_RawValueChanged_Fired;

        void target_RawValueChanged(object sender, ValueChangedEventArgs<object> e)
        {
            m_RawValueChanged_Fired = true;
        }


        /// <summary>
        ///A test for ValueChanged()
        ///</summary>
        [TestMethod]
        public void ValueChanged_UnitTest()
        {
            SmartField<int> target = new SmartField<int>();
            target.ValueChanged += target_ValueChanged;
            m_ValueChanged_Fired = false;
            target.Value = 123;
            Assert.IsTrue(m_ValueChanged_Fired);
            target.ValueChanged -= target_ValueChanged;
        }

        private bool m_ValueChanged_Fired;

        void target_ValueChanged(object sender, ValueChangedEventArgs<int> e)
        {
            m_ValueChanged_Fired = true;
        }

        

        #endregion

        #region Fields and Constants

        private TestContext testContextInstance;

        #endregion
    }
}